package hczc.longcai.com.hccrowdfunding.home.fourth_mine.fragments;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.utils.httputils.LoadDatas;
import hczc.longcai.com.hccrowdfunding.views.CircleImageView;

/**
 * A simple {@link Fragment} subclass.
 */
public class Mine_Data_Head_Fragment extends Fragment {


    private String head;
    private CircleImageView c_head;
    private Mine_Data_Head_Fragment.getHeadAsyncTase getHeadAsyncTase;

    public Mine_Data_Head_Fragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initDatas();
    }

    private void initDatas() {
        Bundle arguments = getArguments();
        head = arguments.getString("head");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine__data__head_, container, false);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));

        initViews(view);




        return view;
    }

    private void initViews(View view) {
        c_head = ((CircleImageView) view.findViewById(R.id.mine_data_head));
        getHeadAsyncTase = new getHeadAsyncTase();
        getHeadAsyncTase.execute(((Void) null));

    }

    class getHeadAsyncTase extends AsyncTask<Void,Void,Bitmap>{

        @Override
        protected Bitmap doInBackground(Void... params) {

            Bitmap bitmap = null;
            byte[] datas = LoadDatas.getDatas(head);
            bitmap = BitmapFactory.decodeByteArray(datas,0,datas.length);

            return bitmap;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
            c_head.setImageBitmap(bitmap);
        }
    }


}
